package cn.wanda.bi.sunshine.platform.server.controller;

import cn.wanda.bi.sunshine.platform.server.aspect.AuthUser;
import cn.wanda.bi.sunshine.platform.server.aspect.CheckLimit;
import cn.wanda.bi.sunshine.platform.server.aspect.Logging;
import cn.wanda.bi.sunshine.platform.server.bean.model.UserLabelAuthMenu;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.ListResponse;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.SimpleResponse;
import cn.wanda.bi.sunshine.platform.server.service.UserLabelAuthMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * Created by wangfupeng1
 */
@Api(description = "菜单接口")
@RestController
@RequestMapping(value = "/v1/menu", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DMPUserLabelAuthMenuController implements Logging {

    public static final Logger logger = LoggerFactory.getLogger(DMPUserLabelAuthMenuController.class);
    @Autowired
    private UserLabelAuthMenuService userLabelAuthMenuService;

    @AuthUser
    @ApiOperation("新增一个新的菜单记录。传入参数：token，用户名，登录时间； 输出数据：UserLabelAuthMenu对象（id，应用id，菜单权限）")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    SimpleResponse<UserLabelAuthMenu> add(@RequestBody UserLabelAuthMenu userLabelAuthMenu,
                                        @ApiParam(value = "登录校验码") @RequestHeader("token") String token
    ) {
        return userLabelAuthMenuService.addUserLabelAuthMenu(userLabelAuthMenu);
    }

    @AuthUser
    @ApiOperation("根据menuId进行查询。传入参数：token，用户名，登录时间； 输出数据：UserLabelAuthMenu对象（id，应用id，菜单权限）")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    SimpleResponse<UserLabelAuthMenu> queryPageById(@ApiParam(value = "menuId") @PathVariable(value = "id") Integer id,
                                              @ApiParam(value = "登录校验码") @RequestHeader("token") String token) {
        return userLabelAuthMenuService.queryUserLabelAuthMenuById(id);
    }

    @AuthUser
    @ApiOperation("更新menuid对应的菜单。传入参数：token，用户名，登录时间； 输出数据：UserLabelAuthMenu对象（id，应用id，菜单权限）")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    SimpleResponse<UserLabelAuthMenu> update(@RequestBody UserLabelAuthMenu userLabelAuthMenu,
                                           @ApiParam(value = "登录校验码") @RequestHeader("token") String token) {
        return userLabelAuthMenuService.updateUserLabelAuthMenu(userLabelAuthMenu);
    }

    @AuthUser
    @ApiOperation("删除id对应的菜单。传入参数：pageId,token,用户名，登录时间； 输出数据：UserLabelAuthMenu对象（id，应用id，菜单权限）")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    SimpleResponse<UserLabelAuthMenu> delete(@ApiParam(value = "pageId") @PathVariable Integer id,
                                          @ApiParam(value = "登录校验码") @RequestHeader("token") String token) {
        return userLabelAuthMenuService.deleteUserLabelAuthMenu(id);
    }

    @CheckLimit
    @AuthUser
    @ApiOperation("查询所有Page菜单项。传入参数：menu页码,menu每页条数,token，用户名，登录时间； 输出数据：UserLabelAuthMenu列表（id，应用id，菜单权限）")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    ListResponse<UserLabelAuthMenu> querymenuList(@ApiParam(value = "menu页码") @RequestParam(value = "index", required = false, defaultValue = "1") Integer index,
                                                  @ApiParam(value = "menu每页条数") @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
                                                  @ApiParam(value = "登录校验码") @RequestHeader("token") String token) {
        return userLabelAuthMenuService.queryUserLabelAuthMenuList(index, limit);
    }


}
